/**
 * Class that contains the OpenLayers filters used.
 *
 * @constructor
 */
function Filters() {
    "use strict";
    
    /**
     * Creates an OpenLayers filter object used for searching on the
     * land survey interface.
     *
     * @param {string} search_property The property of the place to search
     *  for defined on the land survey interface.
     * @param {string} search_term The name of the place to search for
     * @returns An OpenLayers filter object
     */
    this.createFilter = function (search_property, search_term) {
        var filter = new OpenLayers.Filter.Comparison({
            type: OpenLayers.Filter.Comparison.LIKE,
            property: search_property,
            value: search_term,
            wildCard: '*',
            matchCase: false
        });
        return filter;
    };

    /**
     * Combines two OpenLayers filters in a conjunctive way so searching for
     * two or more properties is possible.
     * 
     * @param {object} filter_one An OpenLayers filter object
     * @param {object} filter_two An OpenLayers filter object
     * @returns A filter combining the two given filters into a conjunction
     */
    this.createAndFilter = function (filter_one, filter_two) {
        var and_filter = new OpenLayers.Filter.Logical({
            type: OpenLayers.Filter.Logical.AND,
            filters: [
                filter_one,
                filter_two
            ]
        });
        return and_filter;
    };

    /**
     * Combines two OpenLayers filters in a disjunctive way so searching for
     * two or more properties is possible.
     * 
     * @param {object} filter_one An OpenLayers filter object
     * @param {object} filter_two An OpenLayers filter object
     * @returns A filter combining the two given filters into a disjunction
     */
    this.createOrFilter = function (filter_one, filter_two) {
        var or_filter = new OpenLayers.Filter.Logical({
            type: OpenLayers.Filter.Logical.OR,
            filters: [
                filter_one,
                filter_two
            ]
        });
        return or_filter;
    };

    /**
     * Creates an OpenLayers filter for searching the radius of a given
     * point.
     *
     * @param {object} origin An OpenLayers point object
     * @param {integer} radius The distance from the origin to
     *  search within (meters)
     * @returns An OpenLayers filter for searching for features
     *  within a given circular area
     */
    this.createRadialFilter = function (origin, radius) {
        var filter = new OpenLayers.Filter.Comparison({
            type: OpenLayers.Filter.Spatial.DWITHIN,
            property: 'pnr:paikkaSijainti',
            value: origin,
            distance: (radius * 1000),
            distanceUnits: 'm'
        });
        return filter;
    };

    /**
     * Creates an OpenLayers filter that searches within a
     * given rectangular area
     * 
     * @param {object} An OpenLayers bounds object
     * @returns An OpenLayers filter for searching for features
     *  within the given bounds
     */
    this.createBoundedFilter = function (bounds) {
        var filter = new OpenLayers.Filter.Comparison({
            type: OpenLayers.Filter.Spatial.BBOX,
            property: 'pnr:paikkaSijainti',
            value: bounds
        });
        return filter;
    };
}